package com.ztil.net;

import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;

public class NetUtils {
	public static void main(String[] args) {
		System.out.println(isUsedPort("localhost", 1043));
	}

	/*** 
	 *  true:already in using  false:not using  
	 * @param host 
	 * @param port 
	 * @throws IOException 
	 */
	public static boolean isUsedPort(String host, int port) {
		boolean flag = false;
		Socket socket = null;
		try {
			InetAddress theAddress = InetAddress.getByName(host);
			socket = new Socket(theAddress, port);
			flag = true;
		} catch (IOException e) {
		} finally {
			if (socket != null) {
				try {
					socket.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
		return flag;
	}
}
